#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int minSizeSubarray(vector<int> &nums, int target)
    {
        long long SS = accumulate(nums.begin(), nums.end(), 0LL);
        int ans = target / SS, n = nums.size(), left = 0, w = INT_MAX;
        if ((target %= SS) == 0)
            return ans * n;
        for (int right = 0; right < 2 * n - 1; ++right)
        {
            target -= nums[right % n];
            for (; target < 0 && left != right; left = (left + 1) % n)
                target += nums[left];
            if (target == 0)
                w = min(w, (n + right - left + 1) % n);
        }
        return w == INT_MAX ? -1 : n * ans + w;
    }
};
int main()
{

    // system("pause");
    return 0;
}
